$(function () {
    // 导航栏
    navTitle()
    function navTitle() {
        $.ajax({
            method: 'get',
            url: 'http://122.51.249.55:8060/home/index/index',
            success: function (res) {
                // console.log(res)
                const htmlStr = template('tpl-navList', res.data)
                $('.nav').html(htmlStr)
                // 轮播图
                const sw = res.data.banner
                const htmlStr2 = template('swipe', sw)
                $('.swiper-wrapper').empty()
                $('.swiper-wrapper').html(htmlStr2)
            },
        })
    }

    // 热门推荐
    getHotPicList()
    function getHotPicList() {
        $.ajax({
            url: ' http://124.223.14.236:8060/index/hot',
            type: 'GET',
            success: function (res) {
                // console.log(res)
                const resArr = res.data.list
                // 替换内容
                $('.sticky ul').empty()
                // arrPic[0].src = "http://122.51.249.55:8060/upload/images/20220203/1643875469894.jpg"
                // console.log(arr)
                for (var i = 0; i < resArr.length; i++) {
                    $('.sticky ul').append(`<li class="item"><a target="_blank" href=""><img src="http://124.223.14.236:8060/${resArr[i].pic}" class="thumb" />${resArr[i].title}</a></li>`)
                }
            },
        })
    }

    // 最近更新
    excerpt()
    function excerpt() {
        $.ajax({
            url: 'http://124.223.14.236:8060/index/new?page=1&limit=10',
            success: function (res) {
                // console.log(res)
                const data = res.data.list.data
                const htmlStr = template('excerpt', data)
                $('.con').html(htmlStr)
                // 热门文章
                const htmlStr2 = template('items-02', data)
                $('.items-02').html(htmlStr2)
            },
        })
    }

    // 热门标签
    hotLable()
    function hotLable() {
        $.ajax({
            url: 'http://122.51.249.55:8060/home/index/index',
            success: function (res) {
                const data = res.data.allTag
                const htmlStr = template('widget', data)
                $('.widget_tags_inner').html(htmlStr)
                // 友情链接
                const data2 = res.data.allLink
                for (var i = 0; i < data2.length; i++) {
                    if (data2[i].title === '') {
                        const htmlStr2 = template('link', data2)
                        $('.friendship').html(htmlStr2)
                    }
                }
            },
        })
    }

    // 右侧广告位
    textwidget()
    function textwidget() {
        $.ajax({
            url: 'http://122.51.249.55:8060/home/index/index',
            success: function (res) {
                const data = res.data.sideBanner
                const htmlStr = template('textwidget', data)
                $('.textwidget').html(htmlStr)
            },
        })
    }

    // 底部链接
    linkList()
    function linkList() {
        $.ajax({
            url: 'http://122.51.249.55:8060/home/index/index',
            success: function (res) {
                console.log(res)
                var data = res.data.allLink
                $('.footer .link').empty()
                for (var i = 0; i < data.length; i++) {
                    if (data[i].title !== '') {
                        var htmlStr = `<a href="${data[i].url}" title="${data[i].title}">${data[i].des}</a> <span>|</span>`
                        $('.footer .link').append(htmlStr)
                    }
                }

                // 版权信息
                const wek = res.data.config.list[0].children[1].data
                // console.log(wek);
                // console.log(wek[1].attr_value);
                $('.footer p').html(`<p>&copy; 2021 <a href="${wek[3].attr_value}">${wek[1].attr_value}</a>&nbsp;&nbsp;联系邮箱：${wek[2].attr_value}&nbsp;&nbsp; <a href="">${wek[0].attr_value}</a></p>`)

                // 通知公告
                const group = res.data.config.list[2].children[0].data
                // console.log(group)
                $('.style02 strong').html(group[0].group_value)
                $('.style02 h2').html(group[0].attr_value)
                $('.style02 p').html(group[1].attr_value)
            },
        })
    }

    // 友情链接
    link()
    function link() {
        $.ajax({
            url: 'http://122.51.249.55:8060/home/index/index',
            success: function (res) {
                const htmlStr = template('link', res.data.allLink)
                $('.widget_link').html(htmlStr)
            },
        })
    }
})
